﻿<!-- #include file="mymin.asp" -->
<!--#include file="../74hu/upload.inc"-->
<!--#include file="../74hu/upload_5xsoft.inc"-->
<%
Function forAutoLine_(Str)
	If IsNull(str) Then Exit Function
	str=Trim(str)
	str=Replace(str,chr(13)&chr(10),"\\")
	' str=Replace(str,chr(13),"\\")
	forAutoLine_=str
End Function

Call Head2()

w "<title>发表文章(带附件)</title></head><body><div class=""main400"">"

Server.ScriptTimeOut=999999

dim upload,file,formName,formPath,filename,fileExt,filesize
dim ranNum,allowsize
dim id,test,title,author,autoline
id=request.querystring("id")

formPath="../../upload/"
allowsize=10*1024*1024'此处即为10 M
If Keyid<>1 And adminsize>0 Then allowsize=adminsize*1024
randomize
ranNum=year(time_now)&month(time_now)&day(time_now)&hour(time_now)&minute(time_now)&second(time_now)&int(90000*rnd)+10000

if adminupload=1 then
	call UpFile2()
else
	call UpFile()
end if

'无惧上传
sub UpFile()
	set upload=new UpFile_Class '建立上传对象
	upload.GetData (allowsize) '取得上传数据

	if upload.err > 0 then
		select case upload.err
		case 1
			Call Error2("请先选择你要上传的文件!")
		case 2
			Call Error2("文件大小超过了限制"&forFileSize(adminsize)&"!请使用ftp上传！")
		end select
		exit sub
	else
		' formPath=upload.form("filepath") '取得文本域的值
		test=upload.form("test")
		title=upload.form("title")
		author=upload.form("author")
		autoline=upload.form("autoline")
		for each formName in upload.file '列出所有上传了的文件
			set file=upload.file(formName) '生成一个文件对象
			filesize=file.filesize
			if filesize=0 then
				Call Error2("请先选择你要上传的文件！")
			end if

			fileEXT=file.fileEXT
			if CheckFileExtSafe(fileEXT)=true then
				Call Error2("文件格式不正确！")
			end if

			filename=formPath&ranNum&"."&fileExt
			if filesize>0 then '如果 FileSize > 0 说明有文件数据
				result=file.SaveToFile(Server.mappath(filename)) '保存文件
				if result="ok" then
					test = CheckFileExt & test
				else
					response.write "<br>Sorry，文件上传失败！<br/>"
				end if
			end if
			set file=nothing
		next
	end if
	set upload=nothing
end sub

'无名上传
sub UpFile2()
	set upload=new upload_5xsoft '建立上传对象
	test=upload.form("test")
	title=upload.form("title")
	author=upload.form("author")
	autoline=upload.form("autoline")
	for each formName in upload.objFile '列出所有上传了的文件
		set file=upload.file(formName) '生成一个文件对象
		filesize = file.filesize
		if filesize=0 then
			Call Error2("请先选择你要上传的文件！")
		end if
		if filesize>allowsize Then
			Call Error2("文件大小超过了限制"&forFileSize(adminsize)&"!请使用ftp上传！")
		end if

		fileExt=file.filename
		fileExt=Right(fileExt,Len(fileExt)-InStrRev(fileExt,"."))

		if CheckFileExtSafe(fileEXT)=true then
			Call Error2("文件格式不正确！")
		end if

		filename=formPath&ranNum&"."&fileExt
		if filesize>0 then '如果 FileSize > 0 说明有文件数据
			result = file.SaveAs(Server.mappath(filename))'保存文件
			if result=FALSE then
				test = CheckFileExt & test
			else
				response.write "<br>Sorry，文件上传失败！<br/>"
			end if
		end if
		set file=nothing
	next
	set upload=nothing
end sub

Function CheckFileExt()
	dim ImgUp
	ImgUp="jpg,jpeg,png,gif,bmp"
	ImgUp=split(ImgUp,",")
	for i=0 to ubound(ImgUp)
		if lcase(fileEXT)=lcase(trim(ImgUp(i))) then
			CheckFileExt="[img]"&filename&"[/img][br]"
			exit Function
		end if
	next
	CheckFileExt="附件:[url="&filename&"]"&ranNum&"."&fileExt&"[/url][br]"
End Function

if id="" or IsNumeric(id)=False then Call Error2("文章类别出错!")

if test="" or title="" or author="" then Call Error2("各项都不能为空")

If IsNumeric(author) Then Call Error2("来源不能是纯数字")

if len(title)>30 or len(author)>15 or len(test)>20000 then Call Error2("标题不要超过30字，来源不要超过15字，文章内容不要超过20000字，分多篇写。这有助于提高效率！")

if ifArticleRepeat(title) then Call error("站内已存在同样标题的文章,请不要重复发表！")

if autoline=1 Then test=forAutoLine_(test)

dim rs
set rs=server.createobject("adodb.recordset")
rs.open "select classid,test,title,hu_author,hu_date from 74hu_article",myconn,1,3
rs.addnew
rs("classid")=id
rs("test")=test
rs("title")=title
rs("HU_date")=time_now
rs("HU_author")=author
rs.update
rs.close
set rs=nothing
w "记录添加成功!"
%><br/>----------<br/>
<a href="adminsmscl.asp?sid=<%=sid%>&amp;id=<%=id%>">[返回文章]</a><br/>
<a href="wzclass.asp?sid=<%=sid%>">[文章分类]</a><%Call Last2%>